package com.wc.AlgoOJ_homework.AlgoOJ_HomeWork2.U_小球称重;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/6 10:50
 * @description http://43.138.190.70:8888/p/LQ1369?tid=65e6b15c27489dab814f8d41
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int M = 10010;
    // bad[i] = 0 表示还没判断, bad[i] = 1 表示是好的,bad[i] = 2,表示可能是坏的
    // 1：如果没有2,说明全是=,那就数0的个数,怀疑
    // 2: 如果有2，那就说明剩下的好的
//    static int[] bad = new int[N];
    static Set<Integer> bad = new HashSet<>();
    static Set<Integer> good = new HashSet<>();

    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        while (m-- > 0) {
            k = sc.nextInt();
            Set<Integer> left = new HashSet<>();
            Set<Integer> right = new HashSet<>();
            for (int i = 1; i <= k; i++) left.add(sc.nextInt());
            for (int i = 1; i <= k; i++) right.add(sc.nextInt());
            String eq = sc.next();
            if (eq.equals("<")) {
                if (bad.isEmpty()) {
                    bad.addAll(left);
                } else {
                    Set<Integer> tmp = new HashSet<>();
                    for (int x : left) {
                        if (bad.contains(x)) {
                            tmp.add(x);
                        }
                    }
                    bad = tmp;
                }
            } else if (eq.equals(">")) {
                if (bad.isEmpty()) {
                    bad.addAll(right);
                } else {
                    Set<Integer> tmp = new HashSet<>();
                    for (int x : right) {
                        if (bad.contains(x)) {
                            tmp.add(x);
                        }
                    }
                    bad = tmp;
                }
            } else {
                good.addAll(left);
                good.addAll(right);
                for (int x : left) {
                    bad.remove(x);
                }
                for (int x : right) {
                    bad.remove(x);
                }
            }
        }
        if (bad.isEmpty()) out.println(n - good.size());
        else out.println(bad.size());
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
